﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCommon { 
    public static class ConsoleHelper
    {
        private static readonly object _objLock = new();

        /// <summary>
        /// 在控制台输出彩色内容
        /// </summary>
        /// <param name="str">文本</param>
        /// <param name="color">颜色</param>
        public static void WriteColorLine(string str, ConsoleColor color=ConsoleColor.White) {
            lock (_objLock) { 
                ConsoleColor currentForeColor = Console.ForegroundColor;
                Console.ForegroundColor = color;
                Console.WriteLine(str);
                Console.ForegroundColor = currentForeColor;
            }
        }

        /// <summary>
        /// 打印错误信息
        /// </summary>
        /// <param name="str"></param>
        /// <param name="color"></param>
        public static void WriteErrorLine(this string str) =>WriteColorLine(str, ConsoleColor.Red);

        /// <summary>
        /// 打印警告信息
        /// </summary>
        /// <param name="str"></param>
        /// <param name="color"></param>
        public static void WriteWorningLine (this string str)=>WriteColorLine(str, ConsoleColor.Yellow);

        /// <summary>
        /// 打印正常信息
        /// </summary>
        /// <param name="str"></param>
        public static void WriteInfoLine(this string str)=>WriteColorLine (str);

        /// <summary>
        /// 打印成功小型
        /// </summary>
        /// <param name="str"></param>
        public static void WriteSuccessLine(this string str)=>WriteColorLine($"{str}", ConsoleColor.Green);
    }
}
